package cn.thornbird.orgsync.model.dingtalk;

import cn.thornbird.orgsync.model.IResponse;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

@Data
public class Response implements IResponse {

    public static final int ERROR_CODE_INVITATION_SENT = 40103;

    public static boolean isPending(Response response) {
        if (response != null && response.errorCode == ERROR_CODE_INVITATION_SENT) {
            return true;
        }
        return false;
    }

    @JsonProperty("request_id")
    private String requestId;

    @JsonProperty("errcode")
    private Integer errorCode;

    @JsonProperty("errmsg")
    private String errorMessage;

    @Override
    public boolean isSuccess() {
        return errorCode != null && (errorCode.intValue() == 0 || errorCode.intValue() == ERROR_CODE_INVITATION_SENT);
    }

}
